﻿using System;
using fastCSharp;

namespace diantou.web.favorite
{
    /// <summary>
    /// 用户收藏关系
    /// </summary>
    [fastCSharp.code.cSharp.webView.clientType(Name = "diantou.userFavorite")]
    struct userFavorite
    {
        /// <summary>
        /// 相关收藏夹
        /// </summary>
        public struct relateFavorite
        {
            /// <summary>
            /// 是否重新加载视图
            /// </summary>
            [fastCSharp.code.cSharp.webView.outputAjax]
            public bool ViewOnly;
            /// <summary>
            /// 用户收藏系
            /// </summary>
            public userFavorite Favorite;
            /// <summary>
            /// 相关收藏top5
            /// </summary>
            private diantou.dataAccess.favorite[] top5;
            /// <summary>
            /// 相关收藏top5
            /// </summary>
            public diantou.dataAccess.favorite[] Top5
            {
                get
                {
                    if (ViewOnly) return null;
                    if (top5 == null)
                    {
                        int count;
                        top5 = diantou.dataAccess.clientCache.Favorite.Get(diantou.dataAccess.tcpCall.favorite.relateIds(diantou.dataModel.favorite.type.Favorite, Favorite.Id, 5, 1, Favorite.UserId, out count));
                        if (top5 == null) top5 = nullValue<diantou.dataAccess.favorite>.Array;
                    }
                    return top5;
                }
            }
        }
        /// <summary>
        /// 收藏
        /// </summary>
        public diantou.dataAccess.favorite Favorite;
        /// <summary>
        /// 收藏标识
        /// </summary>
        [fastCSharp.code.cSharp.webView.outputAjax]
        public int Id
        {
            get { return Favorite == null ? 0 : Favorite.Id; }
        }
        /// <summary>
        /// 用户标识
        /// </summary>
        public int UserId;
        /// <summary>
        /// 用户收藏关系
        /// </summary>
        public userFavorite UserFavorite
        {
            get { return this; }
        }
        /// <summary>
        /// 
        /// </summary>
        public bool IsSelf
        {
            get { return Favorite != null && Favorite.UserId == UserId; }
        }
        /// <summary>
        /// 是否关注
        /// </summary>
        public bool IsFocus
        {
            get
            {
                return UserId != 0 && Id != 0 && diantou.dataAccess.tcpCall.focusFavorite.IsFocus(UserId, Favorite.Id, dataModel.focus.type.Focus);
            }
        }
    }
}
